//
//  nbl_SDK.h
//  nbl_SDK
//  蓝牙锁SDK主入口

//
//  Created by Real on 16/8/26.
//  Copyright © 2016年 newunity. All rights reserved.
//

//#import <UIKit/UIKit.h>



// In this header, you should import all the public headers of your framework using statements like #import <nbl_SDK/PublicHeader.h>
#import <nbl_SDK/nbl_predef.h>
#import <nbl_SDK/nbl_optRecord.h>
#import <nbl_SDK/nbl_lockEvidences.h>
#import <nbl_SDK/nbl_lockUser.h>
#import <nbl_SDK/nbl_optResult.h>
#import <nbl_SDK/nbl_lockStat.h>
#import <nbl_SDK/nbl_lockInfo.h>
#import <nbl_SDK/nbl_optCallback.h>
#import <nbl_SDK/nbl_subsCallback.h>
#import <nbl_SDK/nbl_optRecord.h>


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * SDK入口类定义
 * 所有供APP开发者使用的API均在此类定义
 * SDK运行于单实例模式，只能通过“instance”接口获取实例，不允许用户自行初始化
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@interface nbl_SDK : NSObject

@property (readonly) double             verNum; // 版本号
@property (readonly) NSString* _Nonnull verStr; // 版本字符串
@property (nonatomic) NSString* _Nonnull walletId; // 卡包ID
//使用者的身份类型  1管家(默认) 2租客
@property (nonatomic,assign) NSInteger idType ;
/* 获取SDK实例，获取到的实例可缓存 */
+(nullable nbl_SDK*) instance;

/* 手机蓝牙状态 */
@property (atomic, readonly) BOOL deviceBleOK;

/* SDK设置*/
-(BOOL)setSdkUser: (nonnull nbl_lockUser*) user; // 设置SDK用户，以便使用SDK
-(BOOL)setPersistence: (BOOL) flag; // 设置当前用户的EKEY数据的持久化状态，设为YES后将会缓存EKEY数据，设为NO会清除本地EKEY并不再缓存
-(BOOL)persistenceStat; // 查询当前SDK用户的EKEY持久化状态

/* SDK、蓝牙锁事件订阅 */
-(void)subsEvent: (nonnull NSArray<NSString*>*) events
    withCallback: (nonnull id<nbl_subsCallback>) callback; // 订阅SDK／蓝牙锁事件
-(void)cancelSubsEvent: (nonnull NSArray<NSString*>*) events
          withCallback: (nonnull id<nbl_subsCallback>) callback; // 退订SDK／蓝牙锁事件

/* 蓝牙锁操作 */
// 资源管理
-(BOOL)setObjectiveLock: (nonnull NSString *) sn
               withCPWD: (nullable NSString*) customerPWD
               walletID: (nonnull NSString *) walletId; // 设置目标蓝牙锁
-(void)scanLock: (nullable NSArray<NSString*>*)filter; // 扫描符合条件的蓝牙锁
-(void)releaseLock; // 释放蓝牙锁资源
-(nullable NSString*)keepLock: (nullable id<nbl_optCallback>) callback;// 保持蓝牙锁连接，每成功调用一次断开时间变为当前时间后60秒
-(BOOL)findObjectiveLock:(nonnull NSString *) sn callback: (nullable id<nbl_optCallback>) callback; // 查找目标锁

// 锁操作
-(nullable NSString*)changeDefaultPwd: (nonnull NSString *) pwd
                    timeout: (nullable NSNumber *) timeout
                      times: (nullable NSNumber *) times
                   callback: (nullable id<nbl_optCallback>) callback;  // 修改默认开门密码
-(nullable NSString*)openLock: (nullable NSNumber *) timeout
                        times: (nullable NSNumber *) times
                     callback: (nullable id<nbl_optCallback>) callback; // 开锁
-(nullable NSString*)closeLock: (nullable NSNumber *) timeout
                         times: (nullable NSNumber *) times
                      callback: (nullable id<nbl_optCallback>) callback; // 上锁
-(nullable NSString*)addPwd: (nonnull NSString *) pwd
                    startAt: (nonnull NSString *) startAt
                   expireAt: (nonnull NSString *) expireAt
                    timeout: (nullable NSNumber *) timeout
                      times: (nullable NSNumber *) times
                   callback: (nullable id<nbl_optCallback>) callback;  // 添加开门密码
-(nullable NSString*)extPwd: (uint8_t) pwdID
                    startAt: (nonnull NSString *) startAt
                   expireAt: (nonnull NSString *) expireAt
                    timeout: (nullable NSNumber *) timeout
                      times: (nullable NSNumber *) times
                   callback: (nullable id<nbl_optCallback>) callback;  // 修改开门密码有效期
-(nullable NSString*)addCard: (nonnull NSString *) startAt
                    expireAt: (nonnull NSString *) expireAt
                     timeout: (nullable NSNumber *) timeout
                       times: (nullable NSNumber *) times
                    callback: (nullable id<nbl_optCallback>) callback;  // 添加感应卡
-(nullable NSString*)extCard: (uint8_t) cardID
                     startAt: (nonnull NSString *) startAt
                    expireAt: (nonnull NSString *) expireAt
                     timeout: (nullable NSNumber *) timeout
                       times: (nullable NSNumber *) times
                    callback: (nullable id<nbl_optCallback>) callback;  // 修改感应卡有效期
-(nullable NSString*)qryEvidenceByType: (uint8_t) type
                               timeout: (nullable NSNumber *) timeout
                                 times: (nullable NSNumber *) times
                              callback: (nullable id<nbl_optCallback>) callback;  // 查询感应卡和密码
-(nullable NSString*)delEvidence: (nonnull nbl_lockEvidences*) evidences
                         timeout: (nullable NSNumber *) timeout
                           times: (nullable NSNumber *) times
                        callback: (nullable id<nbl_optCallback>) callback;           // 删除指定的感应卡和密码
-(nullable NSString*)delAllEvidenceByType: (uint8_t) type
                                  timeout: (nullable NSNumber *) timeout
                                    times: (nullable NSNumber *) times
                                 callback: (nullable id<nbl_optCallback>) callback;  // 删除所有的感应卡、密码
// 锁信息
-(nullable NSString*)getLockInfo: (nullable NSNumber *) timeout
                           times: (nullable NSNumber *) times
                        callback: (nullable id<nbl_optCallback>) callback;  // 读取蓝牙锁产品信息
-(nullable NSString*)getLockStat: (nullable NSNumber *) timeout
                           times: (nullable NSNumber *) times
                        callback: (nullable id<nbl_optCallback>) callback;  // 读取蓝牙锁状态
-(nullable NSString*)getRecords: (nullable NSNumber *) timeout
                          times: (nullable NSNumber *) times
                       callback: (nullable id<nbl_optCallback>) callback;  // 读取蓝牙锁开锁记录
-(nullable NSString*)delRecords: (nullable NSNumber *) timeout
                          times: (nullable NSNumber *) times
                       callback: (nullable id<nbl_optCallback>) callback;  // 删除蓝牙锁开锁记录
// 锁设置
-(nullable NSString*)setTime: (nonnull NSString *) time
                     timeout: (nullable NSNumber *) timeout
                       times: (nullable NSNumber *) times
                    callback: (nullable id<nbl_optCallback>) callback;   // 修改蓝牙锁时钟
-(nullable NSString*)setLockStat: (nonnull nbl_lockStat*) stat
                         timeout: (nullable NSNumber *) timeout
                           times: (nullable NSNumber *) times
                        callback: (nullable id<nbl_optCallback>) callback;  // 修改蓝牙锁状态
-(nullable NSString*)changeCPWD: (nonnull NSString *) newPWD
                        timeout: (nullable NSNumber *) timeout
                          times: (nullable NSNumber *) times
                       callback: (nullable id<nbl_optCallback>) callback;  // 修改用户侧安全密码
-(nullable NSString*)forbidRandomPwd: (nullable NSNumber *) timeout
                               times: (nullable NSNumber *) times
                            callback: (nullable id<nbl_optCallback>) callback;  // 禁止随机密码功能
-(nullable NSString*)allowRandomPwd: (nullable NSNumber *) timeout
                              times: (nullable NSNumber *) times
                           callback: (nullable id<nbl_optCallback>) callback;  // 开启随机密码功能

/* 添加表
 
    *tableNumBer 是12位的数字字符串
    *tableType和tablePort参数从“nbl_predef.h”参考
 
 */
-(nullable NSString*)addTable: (nonnull NSString *) tableNumBer
                         type: (uint8_t) tableType
                         port: (uint8_t) tablePort
                      timeout: (nullable NSNumber *) timeout
                        times: (nullable NSNumber *) times
                     callback: (nullable id<nbl_optCallback>) callback;

// 查询表
-(nullable NSString*)queryTableTimeout: (nullable NSNumber *) timeout
                                 times: (nullable NSNumber *) times
                              callback: (nullable id<nbl_optCallback>) callback;

// 删除表 tableNumBer 是12位的数字字符串
-(nullable NSString*)deleteTable:(nonnull NSString *) tableNumBer
                         timeout: (nullable NSNumber *) timeout
                           times: (nullable NSNumber *) times
                        callback: (nullable id<nbl_optCallback>) callback;

/* 拉合闸
 
    *tableNumBer 是12位的数字字符串
    *switchType参数从“nbl_predef.h”参考
 
*/
-(nullable NSString*)switchTable:(nonnull NSString *) tableNumBer
                          switchType: (uint8_t) switchType
                         startAt: (nonnull NSString *) startAt
                         timeout: (nullable NSNumber *) timeout
                           times: (nullable NSNumber *) times
                        callback: (nullable id<nbl_optCallback>) callback;
// 读取水电表月冻结数据    month 上几个月（1-12）
-(nullable NSString*)getFreezeTableData:(nonnull NSString *) tableNumBer
                             lastMonth: (uint8_t) month
                                timeout: (nullable NSNumber *) timeout
                                  times: (nullable NSNumber *) times
                               callback: (nullable id<nbl_optCallback>) callback;

// 读取水电表当前数据
-(nullable NSString*)getCurrentMonthTableData:(nonnull NSString *) tableNumBer
                                      timeout: (nullable NSNumber *) timeout
                                        times: (nullable NSNumber *) times
                                     callback: (nullable id<nbl_optCallback>) callback;

/* 蓝牙锁生产 */
-(nullable NSString*)initializeLock: (nonnull NSString*) orgSN
                             withSN:(nonnull NSString*) sn
                           callback: (nullable id<nbl_optCallback>)callback; // 初始化蓝牙锁

/* 凭证操作 */
-(BOOL) testEkey: (nonnull NSString *) sn; // 检查指定的ekey是否已经下载到本地
-(BOOL) downloadEkey: (nonnull NSString *) sn
             timeout: (nullable NSNumber*) seconds; // 从凭证服务器下载指定蓝牙锁的电子钥匙
-(BOOL) delEkey: (nonnull NSString *) sn
        timeout: (nullable NSNumber*) seconds; // 删除指定蓝牙锁的全部电子钥匙
-(void) eraseEkeyBuff: (nullable NSString*) sn; // 从内存和硬盘中清除指定SN的蓝牙锁的EKEY，不指定SN则清除当前用户下所有

@end
